#include "TContext.h"

#include <QDateTime>
#include <QDir>

TContext* TContext::_instance = NULL;

TContext::TContext()
{
    QDir dir(TConfig::instance()->logPath());
    if(!dir.exists())
    {
        QDir tempDir;
        tempDir.mkdir(dir.absolutePath());
    }

    _config = TConfig::instance();
    _logger = new TLogger(dir.absoluteFilePath(QDateTime::currentDateTime().toString("yyyyMMdd_hhmmss")+".log"));
}

TContext::~TContext()
{
    delete _requsterFactory;
}

IContext* TContext::instance()
{
    if(NULL == _instance)
    {
        _instance = new TContext();
    }
    return _instance;
}

TRequesterFactory* TContext::requesterFactory()
{
    return _requsterFactory;
}

TLogger* TContext::logger()
{
    return _logger;
}

TConfig* TContext::config()
{
    return _config;
}

TDesktop* TContext::desktop()
{
    return this->_desktop;
}

void TContext::setDesktop(TDesktop *desktop)
{
    this->_desktop = desktop;
}

